//
// TFT_4DGL is a class to drive 4D Systems TFT touch screens
//
// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
//
// TFT_4DGL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// TFT_4DGL is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with TFT_4DGL.  If not, see <http://www.gnu.org/licenses/>.

#ifndef Bike_Display_4dSystems_Functions_H_
#define Bike_Display_4dSystems_Functions_H_

#include <plib.h>
#include "Bike_Display_Bitmap_Definitions.h"
#include <stdbool.h>

// 4DGL Functions values
#define AUTOBAUD        0x55
#define CLS             0x45
#define BAUDRATE        0x51
#define VERSION         0x56
#define BCKGDCOLOR      0x42
#define DISPCONTROL     0x59
#define SETVOLUME       0x76
#define CIRCLE          0x43
#define TRIANGLE        0x47
#define LINE            0x4C
#define RECTANGLE       0x72
#define ELLIPSE         0x65
#define PIXEL           0x50
#define READPIXEL       0x52
#define SCREENCOPY      0x63
#define PENSIZE         0x70
#define SETFONT         0x46
#define TEXTMODE        0x4F
#define TEXTCHAR        0x54
#define GRAPHCHAR       0x74
#define TEXTSTRING      0x73
#define GRAPHSTRING     0x53
#define TEXTBUTTON      0x62
#define GETTOUCH        0x6F
#define WAITTOUCH       0x77
#define SETTOUCH        0x75


// Screen answers
#define ACK             0x06
#define NAK             0x15

// Screen states
#define OFF             0x00
#define ON              0x01

// Graphics modes
#define SOLID           0x00
#define WIREFRAME       0x01

// Text modes
#define TRANSPARENT     0x00
#define OPAQUE          0x01

// Fonts Sizes
#define FONT_5X7        0x00
#define FONT_8X8        0x01
#define FONT_8X12       0x02
#define FONT_12X16      0x03

// Touch Values
#define WAIT            0x00
#define PRESS           0x01
#define RELEASE         0x02
#define MOVE            0x03
#define STATUS          0x04
#define GETPOSITION     0x05

// Data speed
#define BAUD_110        0x00
#define BAUD_300        0x01
#define BAUD_600        0x02
#define BAUD_1200       0x03
#define BAUD_2400       0x04
#define BAUD_4800       0x05
#define BAUD_9600       0x06
#define BAUD_14400      0x07
#define BAUD_19200      0x08
#define BAUD_31250      0x09
#define BAUD_38400      0x0A
#define BAUD_56000      0x0B
#define BAUD_57600      0x0C
#define BAUD_115200     0x0D
#define BAUD_128000     0x0E
#define BAUD_256000     0x0F

// Mode data
#define BACKLIGHT       0x00
#define DISPLAY         0x01
#define CONTRAST        0x02
#define POWER           0x03
#define ORIENTATION     0x04
#define TOUCH_CTRL      0x05
#define IMAGE_FORMAT    0x06
#define PROTECT_FAT     0x08

// change this to your specific screen (newer versions) if needed
// Startup orientation is PORTRAIT so SIZE_X must be lesser than SIZE_Y
#define SIZE_X          320
#define SIZE_Y          240

#define IS_LANDSCAPE    0
#define IS_PORTRAIT     1

// Screen orientation
#define LANDSCAPE       0x01
#define LANDSCAPE_R     0x02
#define PORTRAIT        0x03
#define PORTRAIT_R      0x04

// Parameters
#define ENABLE          0x00
#define DISABLE         0x01
#define RESET           0x02

#define NEW             0x00
#define OLD             0x01

#define DOWN            0x00
#define UP              0x01

#define PROTECT         0x01
#define UNPROTECT       0x00

//Colour definitions
#define RED             0xF800
#define GREEN           0x07E0
#define BLUE            0x001F
#define BLACK           0x0000


//**************************************************************************

// Initialisation
void LCDInit(void);

// General Commands
void LCDAutoBaud(void);
void LCDCls(void);
void LCDRestart(void);
void LCDVersion(void);
void LCDBaudRate(long speed);
void LCDDisplayControl(char mode, char value);
void LCDuSDImage(int x, int y, long s);
void LCDSetFont(char mode);

// Touch Command
void LCDTouchMode(char mode);
void LCDGetTouch(void);
char LCDWaitTouch(int delay);
void LCDSetTouch(int x1, int y1, int x2, int y2);
char* LCDTouchStatus(void);
void LCDPauseUntilTouch(int *, int *);
void LCDGetTouchXY(char *, int, int *,int *);

// Texts Commands
void LCDSetFont(char);
void LCDTextMode(char);
void LCDTextChar(char, char, char, int);
void LCDGraphicChar(char, int, int, int, char, char);
void LCDTextString(char *, char, char, char, int);
void LCDGraphicString(char *, int, int, char, int, char, char);
//void LCDTextButton(char *, char, int, int, int, char, int, char, char);
void LCDDrawPixel(int x, int y, int color);
unsigned char LCDGridPosition(void);
void LCDDrawRect(int x1, int y1, int x2, int y2, int colour);

void MyLCDDisplayValue(int nValue, int nValueOnLCD, bool bColourChanged, bool bNegativeChanged, display_colour eStringColour, screen_position eStringPosition);
char LoadFontBMPAddress(void);
/*
void LCDbackground_color(int);
void LCDset_volume(char);


*/

// RS232 Functions
void SendDataBuffer(char *buffer, UINT8 size);
char GetDataBuffer(char *buffer, UINT8 max_size);
void ClearDataBuffer(void);

#endif
